package com.tanhua.server.controller;

import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.vo.NearUserVo;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import com.tanhua.server.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * [交友] 模块
 */
@RestController
@RequestMapping("tanhua")
public class TodayBestController {

    @Autowired
    private TodayBestService todayBestService;

    /**
     * 今日佳人
     */
    @GetMapping("todayBest")
    public ResponseEntity<TodayBest> queryTodayBest() {
        TodayBest todayBest = todayBestService.queryTodayBest();

        return ResponseEntity.ok(todayBest);
    }

    /**
     * 首页推荐用户
     */
    @GetMapping("recommendation")
    public ResponseEntity<PageResult> queryRecommendUserList(RecommendUserQueryParam queryParam) {
        PageResult pageResult = this.todayBestService.queryRecommendUserList(queryParam);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 今日佳人详情
     */
    @GetMapping("{userId}/personalInfo")
    public ResponseEntity<TodayBest> queryTodayBest(@PathVariable("userId") Long userId) {
        TodayBest todayBest = this.todayBestService.queryTodayBestInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查询陌生人问题
     */
    @GetMapping("strangerQuestions")
    public ResponseEntity<String> queryQuestion(@RequestParam("userId") Long userId) {
        String question = this.todayBestService.queryQuestion(userId);
        return ResponseEntity.ok(question);
    }

    /**
     * 回复陌生人问题
     */
    @PostMapping("strangerQuestions")
    public ResponseEntity<Void> replyQuestion(@RequestBody Map<String, Object> param) throws Exception {
        Long userId = Long.valueOf(param.get("userId").toString());
        String reply = param.get("reply").toString();
        Boolean result = this.todayBestService.replyQuestion(userId, reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     */
    @GetMapping("search")
    public ResponseEntity<List<NearUserVo>> queryNearUser(@RequestParam(value = "gender", required = false) String gender,
                                                          @RequestParam(value = "distance", required = false, defaultValue = "200") String distance) {
        List<NearUserVo> list = this.todayBestService.queryNearUser(gender, distance);
        return ResponseEntity.ok(list);
    }

    /**
     * 探花
     */
    @GetMapping("cards")
    public ResponseEntity<List<TodayBest>> queryCardsList() {
        List<TodayBest> list = this.todayBestService.queryCardsList();
        return ResponseEntity.ok(list);
    }

    /**
     * 喜欢（右滑）
     */
    @GetMapping("{userId}/love")
    public ResponseEntity<Void> likeUser(@PathVariable("userId") Long likeUserId) {
        this.todayBestService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 不喜欢（左滑）
     */
    @GetMapping("{userId}/unlove")
    public ResponseEntity<Void> disLikeUser(@PathVariable("userId") Long likeUserId) {
        this.todayBestService.disLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }
}
